home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / osi / isode / dosisode / DOSISODE80.ZIP / ISODE8.WRK / UNIX / LIB / DIR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-01  |  1.1 KB  |  63 lines

  1. #include <string.h>
  2. #include <dir.h>
  3. #include <dirent.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6.  
  7. DIR *opendir(char *name)
  8. {
  9.   DIR *dir;
  10.   struct stat *s;
  11.   int i;
  12.  
  13.   i = stat(name,s);
  14.   if (i == -1) return(NULL);
  15.   dir = (DIR *)malloc(sizeof(DIR));
  16.   dir->num_read = 0;
  17.   dir->name = (char *)malloc(strlen(name)+5);
  18.   strcpy(dir->name, name);
  19.   strcat(dir->name, "/*.*");
  20.   return dir;
  21. }
  22.  
  23. struct dirent *readdir(DIR *dir)
  24. {
  25.   int done;
  26.   if (dir->num_read)
  27.     done = findnext(&dir->ff);
  28.   else
  29.     done = findfirst(dir->name, &dir->ff, FA_ARCH|FA_RDONLY|FA_DIREC);
  30.   if (done)
  31.     return 0;
  32.   dir->num_read ++;
  33.   dir->de.d_namlen = strlen(dir->ff.ff_name);
  34.   strcpy(dir->de.d_name,dir->ff.ff_name);
  35.   strlwr(dir->de.d_name);
  36.   return &dir->de;
  37. }
  38.  
  39. long telldir(DIR *dir)
  40. {
  41.   return dir->num_read;
  42. }
  43.  
  44. void seekdir(DIR *dir, long loc)
  45. {
  46.   int i;
  47.   rewinddir(dir);
  48.   for (i=0; i<loc; i++)
  49.     readdir(dir);
  50. }
  51.  
  52. void rewinddir(DIR *dir)
  53. {
  54.   dir->num_read = 0;
  55. }
  56.  
  57. int closedir(DIR *dir)
  58. {
  59.   free(dir->name);
  60.   free(dir);
  61. }
  62.  
  63.